package com.hualan.zhsq.controller.car;

import com.hualan.zhsq.entity.car.Vehicle;
import com.hualan.zhsq.service.car.VehicleService;
import com.hualan.zhsq.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName VehicleController
 * @Description TODO
 * @Author ZheRan
 * @Date 2025年08月05日 下午9:44
 * @Version 1.0
 */
@RestController
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

    //新增一条数据
    @PostMapping("/vehicle/add")
    public Result add(@RequestBody Vehicle vehicle) {
        return Result.success(vehicleService.add(vehicle));
    }

    //修改一条数据
    @PutMapping("/vehicle/edit")
    public Result edit(@RequestBody Vehicle vehicle) {
        return Result.success(vehicleService.edit(vehicle));
    }

    //根据id逻辑删除一条数据
    @DeleteMapping("/vehicle/remove/{id}")
    public Result remove(@PathVariable Integer id) {
        return Result.success(vehicleService.remove(id));
    }

    //根据ids批量删除数据
    @DeleteMapping("/vehicle/removeBatch")
    public Result removeBatch(Integer[] ids) {
        return Result.success(vehicleService.removeBatch(ids));
    }

    //根据id查询一条数据
    @GetMapping("/vehicle/find/{id}")
    public Result findById(@PathVariable Integer id) {
        return Result.success(vehicleService.findById(id));
    }

    //根据条件查询数据
    @GetMapping("/vehicle/findPage")
    public Result findPage() {
        return Result.success(vehicleService.findPage(1, 10, new Vehicle()));
    }

    /*
     *
     * @Description 多表联查
     * @param pageNum 页码
     * @param pageSize 每页条数
     * @param vehicle 查询条件
     */
    @GetMapping("/vehicle/findPageByResident")
    public Result<Map<String,Object>> findPageByResident (Integer pageNum, Integer pageSize, Vehicle vehicle) {
        return Result.success(vehicleService.vehicleResident(pageNum, pageSize, vehicle));
    }
}
